package com.douyang.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.douyang.dto.LoginDTO;
import com.douyang.base.expcetion.UserException;
import com.douyang.mapper.UserBaseInfoMapper;
import com.douyang.base.model.UserBaseInfo;
import com.douyang.service.AuthService;
import org.springframework.stereotype.Service;

@Service("password")
public class PasswordAuthServiceImpl extends ServiceImpl<UserBaseInfoMapper, UserBaseInfo> implements AuthService{

    @Override
    public UserBaseInfo execute(LoginDTO loginDTO) {
        UserBaseInfo userBaseInfo = lambdaQuery()
                .eq(UserBaseInfo::getUserName, loginDTO.getUserName())
                .one();
        if(userBaseInfo == null){throw new UserException("账号或密码错误");}
        if(!userBaseInfo.getPassword().equals(loginDTO.getPassword()))throw new UserException("账号或密码错误");
        userBaseInfo.setPassword(null);
        return userBaseInfo;
    }
}
